<?php
/**
 * 版本:酷享云支付3.0版
 * 作者：余生
 * 官网：www.kuxiangcms.com
 * 技术QQ：2316803263
 * 酷享云支付官网:pay.kuxiangcms.cn
**/
//商户列表
include("../includes/common.php");
include './head.php';
if($islogin==1){}else exit("<script language='javascript'>window.location.href='./login.php';</script>");
?> 

 <div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a>
                    <cite>商户列表</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
            </a>
        </div>

         <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                       <div class="layui-card-body ">
<?php

$my=isset($_GET['my'])?$_GET['my']:null;

if($my=='add')
{

echo '<div class="layui-tab page-content-wrap layui-card">
';
echo '

<form class="layui-form" action="./ulist.php?my=add_submit" method="POST">
  <div class="layui-input-inline layui-form-item layui-show-xs-block">
  <label class="layui-form-label">结算方式:</label>
  <div class="layui-input-block">
  <select class="form-control" name="settle_id">
'.($conf['stype_1']?'<option value="1">支付宝</option>':null).'
'.($conf['stype_2']?'<option value="2">微信</option>':null).'
'.($conf['stype_3']?'<option value="3">QQ钱包</option>':null).'
'.($conf['stype_4']?'<option value="4">银行卡</option>':null).'
</select>
</div>
</div>
<div class="layui-form-item">
              <label class="layui-form-label">会员账号:</label>
              <div class="layui-input-block">
            <input type="text"  autocomplete="off" required="" class="layui-input" name="name" value="">
              </div>
            </div>

            <div class="layui-form-item">
              <label class="layui-form-label">结算账号:</label>
              <div class="layui-input-block">
            <input type="text"  autocomplete="off" required="" class="layui-input" name="account" value="">
              </div>
            </div>
<div class="layui-form-item">
              <label class="layui-form-label">结算账号姓名:</label>
              <div class="layui-input-block">
            <input type="text"  autocomplete="off" required="" class="layui-input" name="username" value="">
              </div>
            </div>            
<div class="layui-form-item">
              <label class="layui-form-label">网站域名:</label>
              <div class="layui-input-block">
            <input type="text"  autocomplete="off" class="layui-input" name="url" value="" placeholder="可留空">
              </div>
            </div>   
<div class="layui-form-item">
              <label class="layui-form-label">邮箱:</label>
              <div class="layui-input-block">
            <input type="text"  autocomplete="off" class="layui-input" name="email" value="" placeholder="可留空">
              </div>
            </div>   

<div class="layui-form-item">
              <label class="layui-form-label">ＱＱ:</label>
              <div class="layui-input-block">
            <input type="text"  autocomplete="off" class="layui-input" name="qq" value="" placeholder="可留空">
              </div>
            </div>   

<div class="layui-form-item">
              <label class="layui-form-label">自定义分成比例:</label>
              <div class="layui-input-block">
            <input type="text"  autocomplete="off" class="layui-input" name="rate" value="" placeholder="填写百分数，例如98.5">
              </div>
            </div>

 <div class="layui-input-inline layui-form-item layui-show-xs-block">
  <label class="layui-form-label">是否结算:</label>
  <div class="layui-input-block">
  <select class="form-control" name="type">
  <option value="1">1_是</option>
  <option value="2">2_否</option>
  </select>
</div>
</div>
 <div class="layui-input-inline layui-form-item layui-show-xs-block">
  <label class="layui-form-label">是否激活:</label>
  <div class="layui-input-block">
 <select class="form-control" name="active">
 <option value="1">1_激活</option>
 <option value="0">0_封禁</option>
 </select>
</div>
</div>
<div class="layui-input-inline layui-form-item layui-show-xs-block">
  <label class="layui-form-label">商户等级:</label>
  <div class="layui-input-block">
<select class="form-control" name="level" default="'.$row['level'].'">
<option value="1">普通商户</option>
<option value="2">黄金vip</option>
<option value="3">钻石vip</option>
</select>
</div>
</div>
<div class="layui-input-inline layui-form-item layui-show-xs-block">
  <label class="layui-form-label">转账功能:</label>
  <div class="layui-input-block">
<select class="form-control" name="usera" default="'.$row['usera'].'">
<option value="0">正常</option>
<option value="1">冻结</option>
</select>
</div>
</div>
<div class="layui-form-item">
              <label class="layui-form-label">等级到期时间:</label>
              <div class="layui-input-block">
            <input type="text"  autocomplete="off" required class="layui-input" name="level_endtime" value="'.date('Y-m-d H:i:s',$row['level_endtime']).'" >
              </div>
            </div>
<div class="layui-form-item">
              <label class="layui-form-label">安全码:</label>
              <div class="layui-input-block">
            <input type="text"  autocomplete="off" class="layui-input" name="safecode" value="'.$row['safecode'].'" placeholder="可留空">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">登入密码:</label>
              <div class="layui-input-block">
            <input type="text"  autocomplete="off" class="layui-input" name="pwd" value="" required="" placeholder="必须填写">
              </div>
            </div>

  <div class="layui-form-item">
              <div class="layui-input-block">
              <input type="submit" value="确定添加" class="layui-btn layui-btn-normal layui-btn-sm  "/>
              </div>
            </div>
</form>';
}
elseif($my=='edit')
{
$id=$_GET['id'];
$row=$DB->query("select * from pay_user where id='$id' limit 1")->fetch();
echo '

<div class="layui-tab page-content-wrap layui-card">
';
echo '
<form class="layui-form" action="./ulist.php?my=edit_submit&id='.$id.'" method="POST">
  <div class="layui-input-inline layui-form-item layui-show-xs-block">
  <label class="layui-form-label">结算方式:</label>
  <div class="layui-input-block">
  <select class="form-control" name="settle_id" default="'.$row['settle_id'].'">
'.($conf['stype_1']?'<option value="1">支付宝</option>':null).'
'.($conf['stype_2']?'<option value="2">微信</option>':null).'
'.($conf['stype_3']?'<option value="3">QQ钱包</option>':null).'
'.($conf['stype_4']?'<option value="4">银行卡</option>':null).'
</select>
</div>
</div>
<div class="layui-form-item">
              <label class="layui-form-label">会员账号:</label>
              <div class="layui-input-block">
            <input type="text"  autocomplete="off" required="" class="layui-input" name="name" value="'.$row['name'].'">
              </div>
              </div>
              <div class="layui-form-item">
              <label class="layui-form-label">结算账号:</label>
              <div class="layui-input-block">
            <input type="text"  autocomplete="off" required="" class="layui-input" name="account" value="'.$row['account'].'">
              </div>
            </div>
<div class="layui-form-item">
              <label class="layui-form-label">结算账号姓名:</label>
              <div class="layui-input-block">
            <input type="text"  autocomplete="off" required="" class="layui-input" name="username" value="'.$row['username'].'">
              </div>
            </div>
<div class="layui-form-item">
              <label class="layui-form-label">商户余额:</label>
              <div class="layui-input-block">
            <input type="text"  autocomplete="off" required="" class="layui-input" name="money" value="'.$row['money'].'">
              </div>
            </div>
<div class="layui-form-item">
              <label class="layui-form-label">网站域名:</label>
              <div class="layui-input-block">
            <input type="text"  autocomplete="off" required="" class="layui-input" name="url" value="'.$row['url'].'">
              </div>
            </div>
 <div class="layui-form-item">
              <label class="layui-form-label">邮箱:</label>
              <div class="layui-input-block">
            <input type="text"  autocomplete="off" class="layui-input" name="email" value="'.$row['email'].'"  placeholder="可留空">
              </div>
            </div>           
 <div class="layui-form-item">
              <label class="layui-form-label">ＱＱ:</label>
              <div class="layui-input-block">
            <input type="text"  autocomplete="off"  class="layui-input" name="qq" value="'.$row['qq'].'"  placeholder="可留空">
              </div>
            </div>           
<div class="layui-form-item">
              <label class="layui-form-label">自定义分成比例:</label>
              <div class="layui-input-block">
            <input type="text"  autocomplete="off" class="layui-input" name="rate" value="'.$row['rate'].'"  placeholder="填写百分数，例如98.5">
              </div>
            </div>           
<div class="layui-input-inline layui-form-item layui-show-xs-block">
  <label class="layui-form-label">是否结算:</label>
  <div class="layui-input-block">
  <select class="form-control" name="type" default="'.$row['type'].'">
  <option value="1">1_是</option>
  <option value="2">2_否</option>
  </select>
</div>
</div>          
<div class="layui-input-inline layui-form-item layui-show-xs-block">
  <label class="layui-form-label">是否激活:</label>
  <div class="layui-input-block">
  <select class="form-control" name="active" default="'.$row['active'].'">
  <option value="1">1_激活</option>
  <option value="0">0_封禁</option>
  </select>
</div>
</div> 
<div class="layui-input-inline layui-form-item layui-show-xs-block">
  <label class="layui-form-label">重置密钥？:</label>
  <div class="layui-input-block">
  <select class="form-control" name="resetkey">
  <option value="0">0_否</option>
  <option value="1">1_是</option>
  </select>
</div>
</div>
<br> 
<div class="layui-input-inline layui-form-item layui-show-xs-block">
  <label class="layui-form-label">商户等级:</label>
  <div class="layui-input-block">
  <select class="form-control" name="level" default="'.$row['level'].'">
  <option value="1">普通商户</option>
  <option value="2">黄金vip</option>
  <option value="3">钻石vip</option>
  </select>
</div>
</div>
<div class="layui-input-inline layui-form-item layui-show-xs-block">
  <label class="layui-form-label">转账状态:</label>
  <div class="layui-input-block">
  <select class="form-control" name="usera" default="'.$row['usera'].'">
  <option value="1">冻结</option>
  <option value="0">正常</option>
  </select>
</div>
</div>  
<div class="layui-form-item">
              <label class="layui-form-label">等级到期时间:</label>
              <div class="layui-input-block">
            <input type="text"  autocomplete="off" required="" class="layui-input" name="level_endtime" value="'.date('Y-m-d H:i:s',$row['level_endtime']).'">
              </div>
            </div>
<div class="layui-form-item">
              <label class="layui-form-label">安全码:</label>
              <div class="layui-input-block">
            <input type="text"  autocomplete="off"  class="layui-input" name="safecode" value="'.$row['safecode'].'">
              </div>
            </div>

  <div class="layui-form-item">
              <div class="layui-input-block">
              <input type="submit" value="保存修改" class="layui-btn layui-btn-normal layui-btn-sm  "/>
              </div>
            </div>
</form>
';
echo '</div></div>
<script>
var items = $("select[default]");
for (i = 0; i < items.length; i++) {
	$(items[i]).val($(items[i]).attr("default")||0);
}
</script>';
}
elseif($my=='add_submit')
{
$settle_id=$_POST['settle_id'];
$name=$_POST['name'];
$account=$_POST['account'];
$username=$_POST['username'];
$money='0.00';
$url=$_POST['url'];
$email=$_POST['email'];
$qq=$_POST['qq'];
$type=$_POST['type'];
$rate=$_POST['rate'];
$active=$_POST['active'];
$level=$_POST['level'];
$usera=$_POST['usera'];
$pwd=md5($_POST['pwd']);
$level_endtime=strtotime($_POST['level_endtime']);
$safecode=$_POST['safecode'];
if($account==NULL or $username==NULL){
exit("<script language='javascript'>alert('保存错误,请确保加*项都不为空');window.location.href='./ulist.php';</script>");
}elseif($name==$row['name']){
exit("<script language='javascript'>alert('添加的会员已经存在请重新添加！,');window.location.href='./ulist.php';</script>");
}else {

$key = random(32);
$sds=$DB->exec("INSERT INTO `pay_user` (`name`, `pwd`,`key`, `account`, `username`, `money`, `url`, `addtime`, `type`, `settle_id`, `email`, `qq`, `rate`, `active`, `usera`,`level` ,`level_endtime`,`safecode`) VALUES ('{$name}', '{$pwd}', '{$key}', '{$account}', '{$username}', '{$money}', '{$url}', '{$date}', '{$type}', '{$settle_id}', '{$email}', '{$qq}', '{$rate}', '{$active}', '{$level}', '{$usera}', '{$level_endtime}', '{$safecode}')");
$pid=$DB->lastInsertId();
if($sds){

	exit("<script language='javascript'>alert('添加商户成功！,');window.location.href='./ulist.php';</script>");

}else

	exit("<script language='javascript'>alert('添加商户失败！,');history.go(-1);</script>");
}
}
elseif($my=='edit_submit')
{
$id=$_GET['id'];
$rows=$DB->query("select * from pay_user where id='$id' limit 1")->fetch();
if(!$rows)
	showmsg('当前记录不存在！',3);
$settle_id=$_POST['settle_id'];
$account=$_POST['account'];
$name=$_POST['name'];
$username=$_POST['username'];
$money=$_POST['money'];
$url=$_POST['url'];
$email=$_POST['email'];
$qq=$_POST['qq'];
$type=$_POST['type'];
$rate=$_POST['rate'];
$active=$_POST['active'];
$level=$_POST['level'];
$usera=$_POST['usera'];
$level_endtime=strtotime($_POST['level_endtime']);
$safecode = $_POST['safecode'];
if($account==NULL or $username==NULL or $safecode==NULL){
exit("<script language='javascript'>alert('保存错误,安全码未填写！');window.location.href='./ulist.php';</script>");

} else {
$sql="update `pay_user` set `level_endtime`='{$level_endtime}',`name` ='{$name}',`usera` ='{$usera}',`account` ='{$account}',`username` ='{$username}',`money` ='{$money}',`url` ='{$url}',`type` ='$type',`settle_id` ='$settle_id',`email` ='$email',`qq` ='$qq',`rate` ='$rate',`active` ='$active',`level`='$level',`safecode`='$safecode' where `id`='$id'";
if($_POST['resetkey']==1){
	$key = random(32);
	$sqs=$DB->exec("update `pay_user` set `key` ='{$key}' where `id`='$id'");
}
if($DB->exec($sql)||$sqs)
   exit("<script language='javascript'>alert('修改成功！');window.location.href='./ulist.php';</script>");
else
  exit("<script language='javascript'>alert('修改商户信息成功！');window.location.href='./ulist.php';</script>".$DB->errorCode());
	
}
}
elseif($my=='delete')
{
$id=$_GET['id'];
$rows=$DB->query("select * from pay_user where id='$id' limit 1")->fetch();
if(!$rows)
   exit("<script language='javascript'>alert('当前记录不存在！');window.location.href='./ulist.php';</script>");
$urls=explode(',',$rows['url']);
$sql="DELETE FROM pay_user WHERE id='$id'";
if($DB->exec($sql))
  exit("<script language='javascript'>alert('删除商户成功！');window.location.href='./ulist.php';</script>");

else
   exit("<script language='javascript'>alert('删除商户失败！');window.location.href='./ulist.php';</script>".$DB->errorCode());
}
else
{

echo '<form class="layui-form layui-col-space5" action="ulist.php" method="GET">
       <input type="hidden" name="my" value="search">     
                                <div class="layui-input-inline layui-show-xs-block">
                                    <select name="column" class="form-control">
                                    <option value="id">商户号</option>
                                    <option value="key">密钥</option>
                                    <option value="account">结算账号</option>
                                    <option value="username">结算姓名</option>
                                    <option value="url">域名</option>
                                    <option value="qq">QQ</option>
                                    <option value="phone">手机号码</option>
                                    <option value="email">邮箱</option>
                                    </select>
                                </div>
                              
                                <div class="layui-input-inline layui-show-xs-block">
                                    <input type="text" name="value" placeholder="搜索内容" autocomplete="off" class="layui-input"></div>
                                <div class="layui-input-inline layui-show-xs-block">
                                    <button class="layui-btn"  type="submit" lay-filter="sreach">
                                        <i class="layui-icon">&#xe615;</i></button>
                                </div>
                                &nbsp;
                               <a href="./ulist.php?my=add" class="layui-btn">添加商户</a>&nbsp;
                              <a href="./plist.php" class="layui-btn">合作者商户列表</a>
                            </form>';

if($my=='search') {
	$sql=" `{$_GET['column']}`='{$_GET['value']}'";
	$numrows=$DB->query("SELECT * from pay_user WHERE{$sql}")->rowCount();
	$con='包含 '.$_GET['value'].' 的共有 <b>'.$numrows.'</b> 个商户';
}else{
	$numrows=$DB->query("SELECT * from pay_user WHERE 1")->rowCount();
	$sql=" 1";
	$con='共有 <b>'.$numrows.'</b> 个商户';
}
echo $con;
?>

<div class="layui-card-body ">
                            <table class="layui-table layui-form">
                                <thead>
                                <tr> 
                                <th>商户号/会员账号</th>
                                <th>密钥</th>
                                <th>余额</th>
                                <th>结算账号/姓名</th>
                                <th>域名/添加时间</th>
                                <th>等级</th>
                                <th>状态</th>
                                <th>转账状态</th>
                                <th>操作</th>
                                </tr>
                                </thead>
      <tbody> 
<?php
$pagesize=30;
$pages=intval($numrows/$pagesize);
if ($numrows%$pagesize)
{
 $pages++;
 }
if (isset($_GET['page'])){
$page=intval($_GET['page']);
}
else{
$page=1;
}
$offset=$pagesize*($page - 1);

$rs=$DB->query("SELECT * FROM pay_user WHERE{$sql} order by id desc limit $offset,$pagesize");
while($res = $rs->fetch())
{
if($res['level']==1){
  $res['levels']='普通会员';
  $res['lvcol']='black';}
elseif($res['level']==2){
  $res['levels']='高级会员';
    $res['lvcol']='blue';}
elseif($res['level']==3){
  $res['levels']='钻石会员';
    $res['lvcol']='red';}
echo '<tr><td><b>'.$res['id'].'<br/>'.$res['name'].'</b></td><td>'.$res['key'].'</td><td>'.$res['money'].'</td><td>'.($res['settle_id']==2?'<font color="green">WX:</font>':null).($res['settle_id']==3?'<font color="green">QQ:</font>':null).$res['account'].'<br/>'.$res['username'].'</td><td>'.$res['url'].'<br/>'.$res['addtime']
  .'</td><td><font color='.$res['lvcol'].'>'.$res['levels'].'</font></td><td>'.($res['active']==1?'<font color=green>正常</font>':'<font color=red>封禁</font>').'</td><td>'.($res['usera']==0?'<font color=green>正常</font>':'<font color=red>冻结</font>').'</td>
  <td><a href="./ulist.php?my=edit&id='.$res['id'].'" class="layui-btn layui-btn-normal layui-btn-sm">编辑</a>&nbsp;<a href="./ulist.php?my=delete&id='.$res['id'].'" class="layui-btn layui-btn-sm layui-btn-danger" onclick="return confirm(\'你确实要删除此商户吗？\');">删除</a></td></tr>';
}
?>
         
           </tbody>
        </table>
      </div>

        <div class="layui-card-body ">
                            <div class="page">
                                <div>
<?php
echo'<ul class="pagination">';
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pages;
if ($page>1)
{
echo '<li><a href="ulist.php?page='.$first.$link.'">首页</a></li>';
echo '<li><a href="ulist.php?page='.$prev.$link.'">&laquo;</a></li>';
} else {
echo '<li class="disabled"><a>首页</a></li>';
echo '<li class="disabled"><a>&laquo;</a></li>';
}
for ($i=1;$i<$page;$i++)
echo '<li><a href="ulist.php?page='.$i.$link.'">'.$i .'</a></li>';
echo '<li class="disabled"><a>'.$page.'</a></li>';
for ($i=$page+1;$i<=$pages;$i++)
echo '<li><a href="ulist.php?page='.$i.$link.'">'.$i .'</a></li>';
echo '';
if ($page<$pages)
{
echo '<li><a href="ulist.php?page='.$next.$link.'">&raquo;</a></li>';
echo '<li><a href="ulist.php?page='.$last.$link.'">尾页</a></li>';
} else {
echo '<li class="disabled"><a>&raquo;</a></li>';
echo '<li class="disabled"><a>尾页</a></li>';
}
echo'</ul>';
#分页
}
?> <!--请勿盗卖酷享云支付源码程序 ，如发现盗卖将不提供更新服务，系统由余生网络信息提供技术服务-->
                                    
                                    
                                   </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

   <script>layui.use(['laydate', 'form'],
        function() {
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#start' //指定元素
            });

            //执行一个laydate实例
            laydate.render({
                elem: '#end' //指定元素
            });
        });
      </script>